import { Controller, Get, Query, Post, UseGuards, Req, Body, } from "@nestjs/common";
import { AuthService } from "./auth.service";
import { LoginDto } from "./interfaces/jwt.interface";
import { AuthGuard } from "@nestjs/passport";

@Controller('auth')
export class AuthController{
    constructor(private readonly authService:AuthService){}

    @Get('token')
    async createToken(@Query('userName') userName:string):Promise<any> {
        return await this.authService.createToken(userName);
    }

    @Post('login')
    async login(@Body() loginInfo:LoginDto):Promise<object>{
        return await this.authService.login(loginInfo);
    }

    @Get('logout')
    @UseGuards(AuthGuard())
    async logout(@Req() req){
        return await this.authService.logout(req.user);
    }
}